package com.eco.fanliapp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eco.fanliapp.dao.SyGoodsHistoryPricesMapper;
import com.eco.fanliapp.entity.SyGoodsHistoryPrices;
import com.eco.fanliapp.service.ISyGoodsHistoryPricesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品历史价格表 服务实现类
 */
@Service
public class SyGoodsHistoryPricesServiceImpl extends ServiceImpl<SyGoodsHistoryPricesMapper, SyGoodsHistoryPrices> implements ISyGoodsHistoryPricesService {

    @Autowired
    private SyGoodsHistoryPricesMapper syGoodsHistoryPricesMapper;

    @Override
    public int add(SyGoodsHistoryPrices syGoodsHistoryPrices) {
        QueryWrapper<SyGoodsHistoryPrices> syUserCollectionWrapper = new QueryWrapper<>();
        syUserCollectionWrapper.eq("enable", 1);
        syUserCollectionWrapper.eq("deleted", 0);
        syUserCollectionWrapper.eq("item_id", syGoodsHistoryPrices.getItemId());
        syUserCollectionWrapper.eq("item_price", syGoodsHistoryPrices.getItemPrice());
        syUserCollectionWrapper.eq("item_price_date", syGoodsHistoryPrices.getItemPriceDate());
        List<SyGoodsHistoryPrices> listOne = syGoodsHistoryPricesMapper.selectList(syUserCollectionWrapper);
        int i = 1;
        if (listOne.size() < 1) {
            i = syGoodsHistoryPricesMapper.insert(syGoodsHistoryPrices);
        }
        return i;
    }
}
